#ifndef GENIE_DISPLAY
#define GENIE_DISPLAY

#include "common.h"

#define MINUS_SIGN 0x80


typedef union
{
   UINT16  word;
   struct
   {
      UINT8  bSevenLeft;
      UINT8  bSevenRight;
   } field;
   struct
   {
      UINT16  a_l: 1;
      UINT16  b_l: 1;
      UINT16  c_l: 1;
      UINT16  d_l: 1;
      UINT16  e_l: 1;
      UINT16  f_l: 1;
      UINT16  g_l: 1;
      UINT16  pd_l: 1;
      UINT16  a_r: 1;
      UINT16  b_r: 1;
      UINT16  c_r: 1;
      UINT16  d_r: 1;
      UINT16  e_r: 1;
      UINT16  f_r: 1;
      UINT16  g_r: 1;
      UINT16  pd_r: 1;
   } led;
} Display_t;

//#define LED_BIT_16(xYz) xYz ## .led.pd_r

typedef union
{
   UINT8 byte;
   struct
   {
      UINT8 filler: 4;
      UINT8 l1: 1;
      UINT8 l4: 1;
      UINT8 l3: 1;
      UINT8 l2: 1;
   } led;
} Leds_t;

//extern Leds_t Leds;
extern Display_t Display;

extern const UINT8 Seg7_Hex[];
extern const UINT8 Seg7_Asc[];


#define LED_ON 1
#define LED_OFF 0

struct display_platform
{
   Display_t Display;
   UINT8 bFlashTimer;
   UINT16 bFlashTimer2;
   UINT8 bButtonLeds;      //
   UINT8 bChargePercent;

   UINT8 fReady: 1;
   UINT8 fFault: 1;
   // test
#if 0
   UINT8 fLevel: 1;
#endif
};

//
// Note: it must be i a whole number of system cycles.
//
#define DISPLAY_CYCLE    50        // milliseconds.

#define DISPLAY_RATE    ((DISPLAY_CYCLE/SYSTEM_CYCLE) - 1)

#define DISPLAY_250MS    (250l/DISPLAY_CYCLE)        // 250 milliseconds
#define DISPLAY_500MS    (500l/DISPLAY_CYCLE)        // 500 milliseconds
#define DISPLAY_10SEC    (10000l/DISPLAY_CYCLE)      // 10 seconds
#define DISPLAY_1SEC     (1000l/DISPLAY_CYCLE)      // 1 secdond
#define DISPLAY_2SEC     (2000l/DISPLAY_CYCLE)      // 2 secdond
#define DISPLAY_4SEC     (4000l/DISPLAY_CYCLE)      // 4 secdond
extern struct display_platform DISPLAY_Platform;

extern void DISPLAY_Init(void);
extern void DISPLAY_Task(void);
extern void update_leds(void);

void ECU_HEX(UINT8 CoDe);
void ECU_ASC(UINT8 l, UINT8 r, UINT8 d);


#endif
